// Auth.cpp: implementation of the CAuth class.
//
//////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "../Frame/GYWalkAidApp.h"
#include "Auth.h"
#include "HardDriveSerialNumer.h"
#include "../Common/CommonFun.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

TCHAR CAuth::m_szComputerID[MAX_PATH] = {0};

CAuth::CAuth()
{
}

CAuth::~CAuth()
{
}

CString CAuth::GetComputerID()
{
	if(_tcslen(m_szComputerID) == 0)
	{
		TCHAR szComputerInfo[MAX_PATH] = {0};

		MasterHardDiskSerial mhds;
		mhds.GetSerialNo(szComputerInfo, sizeof(szComputerInfo));
		
		char szchCPU[MAX_PATH] = {0};
		__asm
		{
			mov eax, 80000004h
			cpuid
			mov dword ptr szchCPU,		eax
			mov dword ptr szchCPU[+4],	ebx
			mov dword ptr szchCPU[+8],	ecx
			mov dword ptr szchCPU[+12],	edx
		}
		

#ifdef _UNICODE
		TCHAR szwcharCPU[MAX_PATH] = {0};
		::MultiByteToWideChar(CP_UTF8, NULL, szchCPU, -1, szwcharCPU, sizeof(szwcharCPU));
		_tcscat(szComputerInfo, szwcharCPU);
#else
		_tcscat(szComputerInfo, szchCPU);
#endif

		CString strEncryptedId = EncryptString(szComputerInfo);
		_tcscpy(m_szComputerID, strEncryptedId);
	}

	return m_szComputerID;
}

